﻿using DotNetExtensions.Core.Encryptions;
using DotNetExtensions.Core.FileTransfers;
using DotNetExtensions.Core.Restful;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Habi.Server.Models;
using Habi.Server.Repositorys;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Habi.Server.Controllers
{
    [Route("api/[controller]/[action]")]
    public class FileController : ControllerBase
    {
        private readonly SolverDbContext dbContext;
        public FileController()
        {
            dbContext = new SolverDbContext();
        }

        [HttpPost]
        public ApiResult Upload([FromForm] IFormCollection data)
        {
            string path = @"D:\hxiong\文档\Data";

            var resp = data.Try<ResourceModel>(path);
            if (resp.Completed)
            {
                var resourceModel = resp.ExtraData;

                resourceModel.Path = resp.FileName;

                dbContext.Resources.Insert(resourceModel);
            }
            return ApiResult.OK();
        }
    }
}
